;; import numbers/linear-random.scm data-structures/binary-tree-set.scm data-structures/print-tree.scm
(define (reflect node)
  (lambda (branch leaf)
    (if (null? node)
        (leaf set-empty)
        (branch (set-left node)
                (set-value node)
                (set-right node)))))

(define print-tree (make-tree-printer reflect))

(define (make-random-tree n t)
  (if (< n 0)
      t
      (make-random-tree
       (- n 1)
       (set-add t (modulo (random!) 10)))))

(define tree1 (make-random-tree 10 set-empty))
(define tree2 (make-random-tree 10 set-empty))
(define tree3 (set-union tree1 tree2))
(define tree4 (make-random-tree 5 set-empty))
(define tree5 (set-subtract tree3 tree4))
(define (header text)
  (newline)
  (display text)
  (newline)
  (display "------------------------------")
  (newline))

(header "t1: random tree of [0-9] * 10")
(print-tree tree1)
(header "t2: random tree of [0-9] * 10")
(print-tree tree2)
(header "t3: t1 + t2")
(print-tree tree3)
(header "t4: random tree of [0-9] * 5")
(print-tree tree4)
(header "t5: t3 - t4")
(print-tree tree5)
(header "tree->list: sum of each tree")
(for-each (lambda (t)
            (display (set->list t))
            (display ": ")
            (display (set-fold (lambda (x y) (+ x y)) 0 t))
            (newline))
          (list tree1 tree2 tree3 tree4 tree5))
